﻿#region Using

using System.Collections.Generic;

using Common.Enums;

using GameCommon.Base;
using GameCommon.ComponentInterfaces;

using GameComponent = GameCommon.Components.GameComponent;

#endregion

namespace Menu.Screens.MainMenu
{
    public class MainMenu : ScreenBase
    {
        private readonly List<IAnimation> animations;

        public MainMenu(IScreenChanger changer, object argument)
            : base(changer, argument)
        {
            this.Layer = 2;
            this.animations = new List<IAnimation>();
        }

        public override ScreenEnum Screen
        {
            get
            {
                return ScreenEnum.MainMenu;
            }
        }

        public override void LoadContent()
        {
            this.Components = MenuLoader.Get(ScreenEnum.MainMenu);

            this.SetupAnimations();

            this.AddCommand("Play", this.OnPlay);
            this.AddCommand("Options", this.OnOptions);
            
            this.AddScreen(ScreenEnum.MenuBackground);
        }

        private void SetupAnimations()
        {
            this.Animations.Add(new MainMenuTextFade(this.Components["LT_Play"], 0));
            this.Animations.Add(new MainMenuTextFade(this.Components["LT_Options"], 1));
            this.Animations.Add(new MainMenuTextFade(this.Components["LT_Exit"], 2));
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);

            this.animations.ForEach(x => x.Update(gameTime));
        }

        private void OnPlay(GameComponent sender)
        {
            this.GoToScreen(ScreenEnum.ConnectionScreen);
        }

        private void OnOptions(GameComponent sender)
        {
            this.GoToScreen(ScreenEnum.Options);
        }

        private void GoToScreen(ScreenEnum screen)
        {
            this.RemoveScreen(this.Screen);
            this.AddScreen(screen);
        }
    }
}